package jaoso.framework.service;

import jaoso.framework.domain.Account;
import jaoso.framework.domain.Right;
import jaoso.framework.domain.Role;

import jaoso.framework.exception.AccountAlreadyExistException;
import jaoso.framework.exception.BusinessException;
import jaoso.framework.exception.GroupExistException;
import jaoso.framework.exception.RightExistException;

import java.io.Serializable;

import com.yl.cap.analyst.exceptions.GroupConflictException;

/**
 * @author edgeloner
 * 
 * @since 2004/5/11
 */
public interface SecurityService
{
    /**
     * change account group
     * 
     * @param accountId
     *            account id
     * @param groupId
     *            group id
     * 
     * @throws BusinessException
     *             any error
     */
    void changeAccountRole(Serializable accountId, Serializable groupId)
            throws BusinessException;

    /**
     * create new right
     * 
     * @param right
     *            DOCUMENT ME!
     * 
     * @throws BusinessException
     *             error
     * @throws RightExistException
     *             right already exist
     */
    void createRight(Right right) throws BusinessException, RightExistException;

    /**
     * create group
     * 
     * @param group
     *            Role dto
     * @param rights
     *            right id array
     * @throws BusinessException
     *             any error
     * @throws GroupExistException
     *             if group desc exist
     */
    void createRole(Role group, String[] rights) throws BusinessException,
            GroupExistException;

    /**
     * DOCUMENT ME!
     * 
     * @param id
     *            DOCUMENT ME!
     * 
     * @return DOCUMENT ME!
     *  
     */
    Account findAccountById(Serializable id);

    /**
     * DOCUMENT ME!
     * 
     * @param name
     *            DOCUMENT ME!
     * 
     * @return DOCUMENT ME!
     * 
     * @throws BusinessException
     *             DOCUMENT ME!
     */
    Account findAccountByName(String name) throws BusinessException;

    /**
     * find all account
     * 
     * @return AccountDTO array
     * 
     * @throws BusinessException
     *             any error
     */
    Account[] findAllAccount() throws BusinessException;

    /**
     * find all group
     * 
     * @return Role array
     * 
     * @throws BusinessException
     *             any error
     */
    Role[] findAllGroup() throws BusinessException;

    /**
     * find all right
     * 
     * @return Right array
     * 
     * @throws BusinessException
     *             any error
     */
    Right[] findAllRight() throws BusinessException;

    /**
     * find group by id
     * 
     * @param id
     *            group id
     * 
     * @return group instance
     * 
     * @throws BusinessException
     *             any error
     */
    Role findRoleById(Serializable id) throws BusinessException;

    /**
     * init Security,
     * 
     * @throws BusinessException
     *             service exception
     */
    void initSecurity() throws BusinessException;

    /**
     * login system width JAAS
     * 
     * @param name
     *            account name
     * @param password
     *            password
     * 
     * @return AccountDTO
     * 
     * @throws BusinessException
     *             if login faile throw a exception
     */
    Account login(String name, String password) throws BusinessException;

    /**
     * register a new account
     * 
     * @param account
     *            AccountDTO
     * 
     * @throws BusinessException
     *             any error
     * @throws AccountAlreadyExistException
     *             if name already exist
     */
    void register(Account account) throws BusinessException,
            AccountAlreadyExistException;

    /**
     * remove account frome database
     * 
     * @param id
     *            AccountDTO id
     * 
     * @throws BusinessException
     *             any error
     */
    void removeAccount(Serializable id) throws BusinessException;

    /**
     * remove account frome database
     * 
     * @param ids
     *            AccountDTO id array
     * 
     * @throws BusinessException
     *             any error
     */
    void removeAccount(Serializable[] ids) throws BusinessException;

    /**
     * remove right
     * 
     * @param ids
     *            id array
     * 
     * @throws BusinessException
     *             any error
     */
    void removeRight(Serializable[] ids) throws BusinessException;

    /**
     * remove group
     * 
     * @param ids
     *            id array
     * 
     * @throws BusinessException
     *             any error
     */
    void removeRole(Serializable[] ids) throws BusinessException,AccountAlreadyExistException;

    /**
     * update account info
     * 
     * @param account
     *            AccountDTO
     * 
     * @throws BusinessException
     *             any error
     * @throws AccountAlreadyExistException
     *             if name already exist
     */
    void updateAccount(Account account) throws BusinessException,
            AccountAlreadyExistException, GroupConflictException;

    /**
     * update right
     * 
     * @param right
     *            RightDTO
     * 
     * @throws BusinessException
     *             any error
     * @throws RightExistException
     *             if right exist
     */
    void updateRight(Right right) throws BusinessException, RightExistException;

    /**
     * update right
     * 
     * @param rights
     *            RightDTO array
     * 
     * @throws BusinessException
     *             any error
     * @throws RightExistException
     *             if right exist
     */
    void updateRight(Right[] rights) throws BusinessException,
            RightExistException;

    /**
     * update group change description, add right or remove right
     * 
     * @param group
     *            group
     * @param removeRight
     *            right id array
     * @param addRight
     *            right id array
     * 
     * @throws BusinessException
     *             any error
     * @throws GroupExistException
     *             if group description exist
     */
    void updateRole(Role group, String[] removeRight, String[] addRight)
            throws BusinessException, GroupExistException;
}